home *** CD-ROM | disk | FTP | other *** search
/ KeyGen Studio 2002 / KeyGen_Studio_2002.iso / Tutorials / Code Inside / Tut12.txt < prev    next >
Encoding:
Text File  |  2001-09-21  |  19.2 KB  |  330 lines

  1. ***********************************************************************************************************************************************************
  2.                 Keygenning4Newbies KeygenMe 4
  3. ***********************************************************************************************************************************************************
  4.  
  5. Author:        Andox
  6. Protection:    Name / Serial
  7. URL:        http://www.leelouonline.com/users/bofh/k4n/kac.zip
  8. Tools:        SoftICE 4.05
  9.  
  10.  
  11. --->    Intro...
  12.  
  13. An old CrackMe but fun to do :), it has some nice little tricks...
  14. Great for practicing :P
  15.  
  16.  
  17. --->    Let's Begin...
  18.  
  19. Open the CrackMe and you'll see some black screen and a "File - Help" menu.
  20. Now go to the Register Dialog by either clicking in the Main Window or selecting "Help/Register".
  21. There you can enter a Name and Serial, just fill something in, i've used:
  22.  
  23. Name:        CoDe_InSiDe
  24. Serial:        1234567890
  25.  
  26. Now get into SoftICE (CTRL+D) and type "bpx hmemcpy" followed by "enter" and out of SoftICE (CTRL+D).
  27. - *BOOM* - SoftICE popups immediately...
  28. Hmmm...Ok...let's continue...
  29. Now disable the breakpoint by typing "BC *" and press (F12) 9 times and you'll see this:
  30.  
  31. -----------------------------------------------------------------------------------------------------------------------------------------------------------
  32.  
  33. :004015CB 83F805                  cmp eax, 00000005            <--- Compare EAX with 05 (Length of Name)
  34. :004015CE 726B                    jb 0040163B                <--- If below we jump and fail, else continue
  35. :004015D0 BED4204000              mov esi, 004020D4            <--- Offset to our Name in ESI
  36. :004015D5 8BC8                    mov ecx, eax                <--- Move EAX in ECX
  37. :004015D7 33C0                    xor eax, eax                <--- XOR EAX which is now 00
  38. :004015D9 8BC6                    mov eax, esi                <--- Move ESI in EAX
  39.  
  40. * Referenced by a (U)nconditional or (C)onditional Jump at Address:
  41. |:004015E6(C)
  42. |
  43. :004015DB 660FBE1E                movsx bx, byte ptr [esi]        <--- Move first Char in BX
  44. :004015DF 03D8                    add ebx, eax                <--- ADD EAX to EBX
  45. :004015E1 0FAFC3                  imul eax, ebx                <--- Multiply EBX with EAX
  46. :004015E4 46                      inc esi                <--- ESI +1
  47. :004015E5 49                      dec ecx                <--- ECX -1
  48. :004015E6 75F3                    jne 004015DB                <--- If ECX is 00 continue, else repeat loop
  49.  
  50. -----------------------------------------------------------------------------------------------------------------------------------------------------------
  51.  
  52. Doesn't look so though :)
  53. It just puts the first Char in BX, ADDs EAX to EBX, Multiplies EBX with EAX, and then repeats this loop till all Chars done.
  54. Notice the weird numbers in the Registers? like ESI was moved to EAX and contains the offset to our Name...
  55. Ok, let's see what's next:
  56.  
  57. -----------------------------------------------------------------------------------------------------------------------------------------------------------
  58.  
  59. :004015E8 0505721800              add eax, 00187205            <--- ADD 00187205 to EAX ???
  60. :004015ED 50                      push eax                <--- Save EAX
  61. :004015EE 6A3C                    push 0000003C                <--- Push the maximum string length to be copied from our "Fake" Serial
  62. :004015F0 68D4204000              push 004020D4                <--- Offset to our "Fake" Serial
  63.  
  64. * Possible Reference to Dialog: DialogID_0064, CONTROL_ID:0068, ""
  65.                                   |
  66. :004015F5 6A68                    push 00000068
  67. :004015F7 FF7508                  push [ebp+08]
  68.  
  69. * Reference To: USER32.GetDlgItemTextA, Ord:0000h
  70.                                   |
  71. :004015FA E8AB000000              Call 004016AA
  72.  
  73. -----------------------------------------------------------------------------------------------------------------------------------------------------------
  74.  
  75. Hmmm... a weird value has been ADDed to EAX (00187205).
  76. And it takes our "Fake" Serial and puts it in 004020D4.
  77. Let's see what's next:
  78.  
  79. -----------------------------------------------------------------------------------------------------------------------------------------------------------
  80.  
  81. :004015FF 5A                      pop edx                <--- EDX now holds the value created out of our Name
  82. :00401600 BFD4204000              mov edi, 004020D4            <--- Move 004020D4 in EDI (points to our "Fake" Serial)
  83. :00401605 660FBE4701              movsx ax, byte ptr [edi+01]        <--- Put the "Second" Char of our "Fake" Serial in AX
  84. :0040160A 3BC2                    cmp eax, edx                <--- Compare EDX with EAX
  85. :0040160C 752D                    jne 0040163B                <--- If not equal we jump and fail, else continue
  86. :0040160E 83F841                  cmp eax, 00000041            <--- Compare 41 (A) with EAX
  87. :00401611 7228                    jb 0040163B                <--- If below we jump and fail, else continue
  88. :00401613 83F85A                  cmp eax, 0000005A            <--- Compare 5A (Z) with EAX
  89. :00401616 7723                    ja 0040163B                <--- If above we jump and fail, else continue
  90. :00401618 BED4204000              mov esi, 004020D4            <--- Move 004020D4 in ESI (Points to our "Fake" Serial)
  91. :0040161D 33FF                    xor edi, edi                <--- XOR EDI which is now 00
  92. :0040161F 3BD0                    cmp edx, eax                <--- Compare EAX with EDX ???
  93. :00401621 7418                    je 0040163B                <--- If equal we jump and fail, else continue
  94. :00401623 6A00                    push 00000000
  95.  
  96. * Possible StringData Ref from Data Obj ->"Registerd"
  97.                                   |
  98. :00401625 688D214000              push 0040218D                <--- This looks nice :)
  99.  
  100. * Possible StringData Ref from Data Obj ->"Program registerd (good work) "
  101.                                         ->":)"
  102.                                   |
  103. :0040162A 6897214000              push 00402197                <--- This looks nice :)
  104. :0040162F 6A00                    push 00000000
  105.  
  106. * Reference To: USER32.MessageBoxA, Ord:0000h
  107.                                   |
  108. :00401631 E8FE000000              Call 00401734
  109. :00401636 E94DFFFFFF              jmp 00401588                <--- Jump to the end
  110.  
  111. -----------------------------------------------------------------------------------------------------------------------------------------------------------
  112.  
  113. Ok, this looks like a normal Registration routine but you probably noticed something strange :)
  114. Because as you see the "cmp eax, edx" at the top, well that looks ok.
  115. If it's not equal we jump and fail else we continue, but if you look a little further down then you'll see a "cmp edx, eax" ???
  116. If equal we jump and fail, So in this piece of Code we will ALWAYS fail :P
  117. Hmmm... tricky...
  118. Ok, what now ???
  119. I suggest to get out of SoftICE and then click "Give up" to close the Register Dialog, why???
  120. Well we know that when we put a breakpoint, SoftICE immediately popups and we haven't even clicked on the "Register" button :/
  121. And the "Registration Routine" we come in then isn't the right way.
  122. So i thought of something...
  123. Now your looking at the Main Window, if you click in it we get the Register Dialog, don't click yet :)
  124. Ok, now get into SoftICE (CTRL+D) and type "bpx hmemcpy" followed by "enter" and then (CTRL+D) again to get out of SoftICE.
  125. Now click in the Main Window and immediately on the "Register" button and SoftICE should popup.
  126.  
  127. --->    There's also some nice thing here :) try putting a breakpoint on "GetDlgItemTextA" and your in for a surprise :P    <---
  128.  
  129. Now press (F12) 9 times and you'll see this:
  130.  
  131. -----------------------------------------------------------------------------------------------------------------------------------------------------------
  132.  
  133. :004013E7 83F805                  cmp eax, 00000005            <--- Compare EAX with 05 (Length of our Name)
  134. :004013EA 0F8263010000            jb 00401553                <--- If below we jump and fail, else continue
  135. :004013F0 A394224000              mov dword ptr [00402294], eax        <--- Save the length of our Name in 00402294
  136. :004013F5 BF98264000              mov edi, 00402698            <--- Move 00402698 in EDI
  137. :004013FA B9B7000000              mov ecx, 000000B7            <--- Move 000000B7 in ECX
  138. :004013FF 33C0                    xor eax, eax                <--- XOR EAX which is now 00
  139. :00401401 F3AA                    repz stosb                <--- Place 00 in EDI, EDI +1, till ECX is 00
  140.  
  141. * Possible StringData Ref from Data Obj ->"                              "
  142.                                         ->"                              "
  143.                                   |
  144. :00401403 BF12274000              mov edi, 00402712            <--- Move 00402712 in EDI
  145.  
  146. * Possible StringData Ref from Data Obj ->"                              "
  147.                                         ->"                              "
  148.                                   |
  149. :00401408 BED5264000              mov esi, 004026D5            <--- Move 004026D5 in ESI
  150.  
  151. -----------------------------------------------------------------------------------------------------------------------------------------------------------
  152.  
  153. Here it Compares our length with 05, if we continue it'll jump and we fail because we haven't entered our Name (We couldn't otherwise we
  154. end up in the bad Registration Routine).
  155. So when your on the "jb 00401553" type "r fl c" followed by "enter" and we can continue.
  156. Then it fills a place with 00.
  157. Now comes the big Algo :)
  158.  
  159. -----------------------------------------------------------------------------------------------------------------------------------------------------------
  160.  
  161. :0040140D C7059B2740003FA7DF89    mov dword ptr [0040279B], 89DFA73F    <--- Move 89DFA73F in 0040279B
  162. :00401417 BA788A3F02              mov edx, 023F8A78            <--- Move 023F8A78 in EDX
  163. :0040141C 8B0D94224000            mov ecx, dword ptr [00402294]        <--- Move the length of our Name in ECX
  164. :00401422 BFAC164000              mov edi, 004016AC            <--- Move 004016AC in EDI
  165. :00401427 8B3F                    mov edi, dword ptr [edi]        <--- Move [EDI] in EDI
  166. :00401429 8B3F                    mov edi, dword ptr [edi]        <--- Move [EDI] in EDI
  167. :0040142B 8B3F                    mov edi, dword ptr [edi]        <--- Move [EDI] in EDI
  168. :0040142D 8BD9                    mov ebx, ecx                <--- Move ECX in EBX
  169. :0040142F 331D9B274000            xor ebx, dword ptr [0040279B]        <--- XOR (89DFA73F) with EBX
  170. :00401435 03DA                    add ebx, edx                <--- ADD EDX to EBX
  171. :00401437 33DA                    xor ebx, edx                <--- XOR EDX with EBX
  172. :00401439 55                      push ebp                <--- Save EBP
  173.  
  174. * Referenced by a (U)nconditional or (C)onditional Jump at Address:
  175. |:004014A5(C)
  176. |
  177. :0040143A A194224000              mov eax, dword ptr [00402294]        <--- Move the length of our Name in EAX
  178. :0040143F E8F9000000              call 0040153D                <--- Check out what happens here, important for the keygen :)
  179. :00401444 660FBE0406              movsx ax, byte ptr [esi+eax]        <--- Move one byte from [ESI+EAX] in AX
  180. :00401449 0FAFC2                  imul eax, edx                <--- Multiply EDX with EAX
  181. :0040144C 33C2                    xor eax, edx                <--- XOR EDX with EAX
  182. :0040144E 41                      inc ecx                <--- ECX +1
  183. :0040144F D3C2                    rol edx, cl                <--- Rotate EDX to the left by CL
  184. :00401451 69C2AEF5B215            imul eax, edx, 15B2F5AE        <--- Multiply 15B2F5AE with EDX and put the result in EAX
  185. :00401457 49                      dec ecx                <--- ECX -1
  186. :00401458 D3E8                    shr eax, cl                <--- Shift EAX to the right by CL
  187. :0040145A 7202                    jb 0040145E                <--- If below we jump and skip one instruction, else continue
  188. :0040145C 13C3                    adc eax, ebx                <--- ADC EBX with EAX
  189.  
  190. * Referenced by a (U)nconditional or (C)onditional Jump at Address:
  191. |:0040145A(C)
  192. |
  193. :0040145E 40                      inc eax                <--- EAX +1
  194. :0040145F 4B                      dec ebx                <--- EBX -1
  195. :00401460 33D8                    xor ebx, eax                <--- XOR EAX with EBX
  196. :00401462 52                      push edx                <--- Save EDX
  197. :00401463 B811000000              mov eax, 00000011            <--- Move 00000011 in EAX
  198. :00401468 E8D0000000              call 0040153D                <--- Check out what happens here, important for the keygen :)
  199. :0040146D 5A                      pop edx                <--- Pop EDX
  200. :0040146E 331C8553274000          xor ebx, dword ptr [4*eax+00402753]    <--- XOR (Some value) with EBX
  201. :00401475 93                      xchg eax,ebx                <--- Switch the Register EBX with EAX
  202. :00401476 C1C810                  ror eax, 10                <--- Rotate EAX to the right with 10
  203. :00401479 8ADC                    mov bl, ah                <--- Move AH to BL
  204. :0040147B 8B2C9D98224000          mov ebp, dword ptr [4*ebx+00402298]    <--- Move (Some value) in EBP
  205. :00401482 8AD8                    mov bl, al                <--- Move AL to BL
  206. :00401484 032C9D98224000          add ebp, dword ptr [4*ebx+00402298]    <--- ADD (Some value) to EBP
  207. :0040148B C1C810                  ror eax, 10                <--- Rotate EAX to the right with 10
  208. :0040148E 8ADC                    mov bl, ah                <--- Move AH to BL
  209. :00401490 332C9D98224000          xor ebp, dword ptr [4*ebx+00402298]    <--- XOR (Some value) with EBP
  210. :00401497 8AD8                    mov bl, al                <--- Move AL to BL
  211. :00401499 032C9D98224000          add ebp, dword ptr [4*ebx+00402298]    <--- ADD (Some value) in EBP
  212. :004014A0 33D5                    xor edx, ebp                <--- XOR EBP with EDX
  213. :004014A2 33FA                    xor edi, edx                <--- XOR EDX with EDI
  214. :004014A4 49                      dec ecx                <--- ECX -1
  215. :004014A5 7593                    jne 0040143A                <--- If ECX is 00 we continue, else we repeat the loop
  216.  
  217. -----------------------------------------------------------------------------------------------------------------------------------------------------------
  218.  
  219. Ok, this is difficult to explain ;)
  220. But at the top it moves a value (89DFA73F) in the address 0040279B, that value will be used for creating an unique value for our Name.
  221.  
  222. I recommend doing this first otherwise you can't find the correct serial for your Name :) --->
  223. type "d 00402294" and then press (ALT+D) now type there the length of your name for me it was:
  224.  
  225. C  o  D  e  _  I  n  S  i  D  e
  226. 01 02 03 04 05 06 07 08 09 0A 0B    Length = 0B
  227.  
  228. then (ALT+D) again to return to the message window now type "d 004026D5" and press (ALT+D) this is for our Name.
  229. Then press TAB and type your Name there.
  230. Then (ALT+D) again to return to the message window now type "d 00402712" and press (ALT+D) this is for our "Fake" Serial.
  231. Then press TAB and type your "Fake" Serial. <---
  232.  
  233. There's some Table at location 00402753 you can look at it with an Hex-Editor :)
  234. And there's also some other big Table at location 00402298 :)
  235. Use them all with your KeyGen.
  236. I suggest just to go slowly through this process to understand it all :)
  237. Let's see what's next:
  238.  
  239. -----------------------------------------------------------------------------------------------------------------------------------------------------------
  240.  
  241. :004014A7 5D                      pop ebp
  242. :004014A8 8BC7                    mov eax, edi                <--- Move EDI in EAX
  243. :004014AA 50                      push eax                <--- Save EAX
  244. :004014AB 6A3C                    push 0000003C                <--- Push maximum string length to be copied from our "Fake" Serial
  245.  
  246. * Possible StringData Ref from Data Obj ->"                              "
  247.                                         ->"                              "
  248.                                   |
  249. :004014AD 6812274000              push 00402712                <--- This is the place for our "Fake" Serial
  250.  
  251. * Possible Reference to Dialog: DialogID_0064, CONTROL_ID:0068, ""
  252.                                   |
  253. :004014B2 6A68                    push 00000068
  254. :004014B4 FF7508                  push [ebp+08]
  255.  
  256. * Reference To: USER32.GetDlgItemTextA, Ord:0000h
  257.                                   |
  258. :004014B7 E8EE010000              Call 004016AA
  259.  
  260. * Possible StringData Ref from Data Obj ->"                              "
  261.                                         ->"                              "
  262.                                   |
  263. :004014BC BE12274000              mov esi, 00402712            <--- ESI now points to our "Fake" Serial
  264.  
  265. -----------------------------------------------------------------------------------------------------------------------------------------------------------
  266.  
  267. And here it takes our "Fake" Serial and puts it in 00402712.
  268. Let's see what's next:
  269.  
  270. -----------------------------------------------------------------------------------------------------------------------------------------------------------
  271.  
  272. :004014C1 33C0                    xor eax, eax                <--- XOR EAX which is now 00
  273. :004014C3 33DB                    xor ebx, ebx                <--- XOR EBX which is now 00
  274. :004014C5 33C9                    xor ecx, ecx                <--- XOR ECX which is now 00
  275. :004014C7 8A1E                    mov bl, byte ptr [esi]        <--- Move first Char of "Fake" Serial in BL
  276.  
  277. * Referenced by a (U)nconditional or (C)onditional Jump at Address:
  278. |:004014DE(C)
  279. |
  280. :004014C9 80EB30                  sub bl, 30                <--- Subtract 30 from BL
  281. :004014CC 8D0480                  lea eax, dword ptr [eax+4*eax]    <--- Move [EAX+4*EAX] in EAX
  282. :004014CF 03C0                    add eax, eax                <--- ADD EAX to EAX
  283. :004014D1 03C3                    add eax, ebx                <--- ADD EBX to EAX
  284. :004014D3 46                      inc esi                <--- ESI +1
  285. :004014D4 8A1E                    mov bl, byte ptr [esi]        <--- Move second Char in BL
  286. :004014D6 41                      inc ecx                <--- ECX +1
  287. :004014D7 83F90A                  cmp ecx, 0000000A            <--- Compare ECX with 0000000A
  288. :004014DA 7404                    je 004014E0                <--- If equal we jump and have put our "Fake" Serial in the Register EAX
  289. :004014DC 84DB                    test bl, bl                <--- Test if BL is 00
  290. :004014DE 75E9                    jne 004014C9                <--- If so we continue, else repeat the loop
  291.  
  292. -----------------------------------------------------------------------------------------------------------------------------------------------------------
  293.  
  294. And here the only thing it does is putting our "Fake" Serial in the Register EAX, after the "jne 004014C9" type "? EAX" to see your "Fake" Serial
  295. in Decimal format.
  296. Now let's see the last stuff:
  297.  
  298. -----------------------------------------------------------------------------------------------------------------------------------------------------------
  299.  
  300. :004014E0 5A                      pop edx                <--- Pop EDX
  301. :004014E1 33D0                    xor edx, eax                <--- XOR EAX with EDX
  302. :004014E3 7505                    jne 004014EA                <--- If the value in EDX is now 00 we continue as Good Guy, else we jump as Bad Guy
  303.  
  304. -----------------------------------------------------------------------------------------------------------------------------------------------------------
  305.  
  306. And here it XORs EAX ("Fake" Serial) with EDX (Our "Real" Serial).
  307. So type here "? EDX" to see your "Real" Serial in Decimal format.
  308. That's it.
  309. I think i need to tell you that i'm not very good at explaining how to KeyGen something :) sorry about this...
  310. But i hope you can KeyGen it in YOUR language, and i hope that you learned something from this.
  311. And don't forget to use that little trick with "GetDlgItemTextA" i told you :)
  312.  
  313. If you have any questions or something send them to:
  314.  
  315. code.inside@home.nl
  316.  
  317.  
  318. --->    Greetings...
  319.  
  320. Everyone from TrickSoft            (www.TrickSoft.net)
  321. Everyone from Cracking4Newbies        (www.Cracking4Newbies.com)
  322. Everyone from Keygenning4Newbies    (Keygenning4Newbies.cjb.net)
  323. And You...
  324.  
  325.             Don't trust the Outside, trust the InSiDe !!!
  326.  
  327.                       Cya...
  328.  
  329.                     CoDe_InSiDe
  330.